package com.example.demo.controller;

import com.example.demo.dbo.User;
import com.example.demo.entity.TUser;
import com.example.demo.event.OrderEvent;
import com.example.demo.service.TUserService;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: demo
 * @description:
 * @author: Mr.Wang
 * @create: 2020-04-28 11:12
 **/
@RestController
public class UserEventTest {

    @Autowired
    private UserService tUserService;

    @Autowired
    private ApplicationContext applicationContext;

    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    //@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public void insertData(@RequestBody User user) {
        System.out.println("ffffffafafa");
        /*User tUser=new User();
        tUser.setUserId("123");
        tUser.setName("同学1");*/
        user.setName(null);
        System.out.println("新建对象：" + user);
        System.out.println("新建对象：" + user.toString());
        List<User> list = new ArrayList<>();
        User user2 = new User();
        user2.setName("222");
        user2.setUserId("222");
        User user3 = new User();
        user3.setName("333");
        user3.setUserId("333");
        User user4 = new User();
        user4.setName("444");
        user4.setUserId("444");
        for (User user1 : list) {
            user1.setUserId("555");
            user1.setName("555");
        }
        System.out.println();

        //tUserService.addData(user);
        /*OrderEvent orderEvent = new OrderEvent(user);
        applicationContext.publishEvent(orderEvent);*/
    }
}
